
import iaa = module("main/org/sdmx/model/v2/base/IdentifiableArtefactAdapter");
import vaa = module("main/org/sdmx/model/v2/base/VersionableArtefactAdapter");
import va = module("main/org/sdmx/model/v2/base/VersionableArtefact");

/**
	* Default implementation of the VersionableArtefact interface. 
	* This class exists as convenience for creating VersionableArtefact 
	* objects.
	* 
	* @author Xavier Sosnovsky, Anthony Morel
	*/
export class VersionableArtefactAdapter extends iaa.IdentifiableArtefactAdapter 
	implements va.VersionableArtefact {

	/*==============================Fields================================*/
		
	private _version:string;
		
	private _validFrom:Date;
		
	private _validTo:Date;
		
	/*===========================Constructor==============================*/
		
	/**
		* Constructs a versionable artefact.
		*  
		* @param id
		* 		The object identifier
		* 
		*/
	constructor(id:string) {
		super(id);
	}
		
	/*============================Accessors===============================*/
		
	/**
		* @inheritDoc 
		*/
	public getVersion():string {
		return this._version;
	}
		
	/**
		* @inheritDoc 
		*/
	public setVersion(version:string) {
		this._version = version;
	}
		
	/**
		* @inheritDoc 
		*/
	public getValidTo():Date {
		return this._validTo;
	}
		
	/**
		* @inheritDoc 
		*/
	public setValidTo(date:Date) {
		if (null != date && 
            !this.validateValidityPeriod(this._validFrom, date)) {
			throw new Error("The validTo date should be after " + 
					"validFrom");
		}
        this._validTo = date;
	}
		
	/**
		* @inheritDoc 
		*/
	public getValidFrom():Date {
        return this._validFrom;
	}
		
	/**
		* @inheritDoc 
		*/
	public setValidFrom(date:Date) {
        if (null != date && null != this._validTo && 
            !this.validateValidityPeriod(date, this._validTo)) {
			throw new Error("The validTo date should be after " + 
				"validFrom");
		}
        this._validFrom = date;
	}
		
	/*=========================Private methods============================*/
		
	private validateValidityPeriod(validFrom:Date, 
		validTo:Date):bool {
		return validFrom.getTime() < validTo.getTime();
	}
}